<?php
/*
 * @Author: AriFe.Liu
 * @Date: 2020-09-21 14:53:06
 * @LastEditors: AriFe.Liu
 * @LastEditTime: 2020-09-21 14:56:52
 * @Description: 
 */

namespace app\admin\model;

use think\Model;


class Banner extends Model
{

    // 表名
    protected $name = 'banner';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'pos_text',
        'show_switch_text',
        'stime_text',
        'etime_text'
    ];
    

    
    public function getTypeList()
    {
        return ['url' => __('Type url'), 'page' => __('Type page'), 'none' => __('Type none')];
    }

    public function getPosList()
    {
        return ['index' => __('Pos index'), 'category' => __('Pos category'), 'exchange' => __('Pos exchange')];
    }

    public function getShowSwitchList()
    {
        return ['0' => __('Show_switch 0'), '1' => __('Show_switch 1')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPosTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pos']) ? $data['pos'] : '');
        $list = $this->getPosList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getShowSwitchTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['show_switch']) ? $data['show_switch'] : '');
        $list = $this->getShowSwitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['stime']) ? $data['stime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getEtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['etime']) ? $data['etime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setStimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setEtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

}
